<?php

namespace app\common\job;

use app\common\model\Member;
use app\common\service\ARYPushService;
use think\Collection;
use think\queue\Job;

/**
 *
 * Class Account
 * @package app\common\job
 */
class Account
{
    /**
     * fire是消息队列默认调用的方法
     * @param Job $job 当前的任务对象
     * @param array|mixed $data 发布任务时自定义的数据
     */
    public function fire(Job $job, $data)
    {
        $ids = $data['ids'];

        $member = Member::getTable();

        Member::whereIn('id', $ids)
            ->tableField(['id'], $member)
            ->select()
            ->each(function ($record) {
                if (!$record->card) {
                    $record->card()->save([], false);
                }

                if (!$record->coin) {
                    $record->coin()->save([], false);
                }
            });

        $job->delete();
    }
}
